Question:
How to change the project in GCP using CLI commands

What is Google Cloud Platform (GCP)?

Google Cloud Platform (GCP) is a comprehensive suite of cloud computing services provided by Google. It provides a range of infrastructure and platform services, such as storage, databases, computing power, machine learning, analytics, and more. GCP enables businesses and developers to build, deploy, and scale applications and services on Google's infrastructure, providing a flexible and scalable cloud computing environment. It competes with other major cloud platforms such as Amazon Web Services (AWS) and Microsoft Azure, offering a range of tools and services to support diverse computing needs in the cloud.


Gcloud console has analytics, real-time messaging, and super-strong security too. Plus, GCP's data centres around the world mean your stuff gets to people faster. Basically, GCP makes tech projects simpler and cooler, like having Google wizards on your side. GCP is designed to help businesses and developers leverage the power of Google's data centres and technology to scale and innovate their applications.


How can you change the project in GCP using CLI commands?

The Google Cloud Platform (GCP) is a strong and flexible place to set up, manage, and grow cloud-based services and apps. While working on different GCP projects, developers and administrators must know how to quickly switch between them using CLI commands. If you want to change projects using CLI commands, this blog post will show you how. This will help you streamline your workflow and manage your GCP resources more easily.


Prerequisites

Before we start, make sure we have these tools:

  • Install the Google Cloud SDK on your local machine. You can obtain a copy by downloading it from the> official documentation.

  • You need a Google Cloud Platform account with two projects.

  • Use the gcloud auth login to verify CLI authentication with Google Cloud Platform.


Steps to Change the Project

The Google Cloud SDK's command-line tool gcloud lets users interact with GCP services and resources. To switch between projects using the CLI, follow these steps:


Step 1: List Projects

Use the following command in order to view the list of projects that are associated with your account:

gcloud projects list

The output of this command will be a table that lists the project IDs, project names, and any other pertinent information for each project.


Step 2: Set the Active Project

To set the active project that you want to work with, use the following command:

gcloud config set project PROJECT_ID

Replace the : PROJECT_ID with the name of the actual project ID of the project you want to switch to.


Step 3: Verify the Project Change

You can use the following command to display the active project in order to check and make sure that the project has been modified without any problems:

gcloud config get-value project

This command will output the project ID of the current active project.


Step 4: Using the New Project

Now that you've changed the active project, any subsequent commands you run using the gcloud CLI will be applied to the newly set project. You can create, manage, and interact with resources in this project directly from the command line.

Let us look at an example to get a better grasp on how this project is switching works.

Assume you have two projects: Project-A (project ID: project-A-2020) and Project-B- (project ID: project-B-8080).

Run the below command to see the list of available projects:

gcloud projects list

You will see a table in front of you that includes Project-A and Project-B along with the project IDs written corresponding to them.

Set the active project to Project-B:

gcloud config set project project-B-8080


Verify the project change:

gcloud config get-value project


You should see the output: project-B-8080, indicating that Project-B is now the active project.


Conclusion

Changing the active project in the Google Cloud Platform using CLI commands is a straightforward process. By following the steps outlined in this tutorial, you can seamlessly switch between projects as you work on different tasks within the GCP environment. This flexibility allows you to efficiently manage and utilize the resources of various projects from the command line


Suggested blogs:

>Step by Step guide to Deploy Terraform in Azure using GitHub Actions

>Testing react components using Hooks and Mocks

>Use Firebase Realtime Database with ASP.NET MVC App

>Use of Singletons in .NET Core in AWS Lambda

>How to do PHP Decryption from Node.js Encryption

>How to Set up the Android emulator?

>How to Set up the local environment for Angular development?

>How to solve encoding issue when writing to a text file, with Python?



Submit
0 Answers